package lesosn03;

public class TesMain5 {
    public static void main(String[] args) {
        String str1 = "hello world";
        char c = str1.charAt(4);
        System.out.println(c);

        // int length(); 字符串的长度
        System.out.println(str1.length());
        System.out.println("中国人".length());

        // int indexOf(str);   获取第一次出现的位置
        System.out.println(str1.indexOf("o"));
        // String replace(old, new);  替换字符串
        System.out.println(str1.replace("o", "X"));
        System.out.println(str1); // final

        // String[] split(String regex); 按正则对字符串拆分
        String[] strs = str1.split("");
        for (int i = 0; i < strs.length; i++) {
            System.out.println(strs[i]);
        }
        String ip = "192.168.1.110";
        String[] ips = ip.split("\\.");
        for (String item: ips) {
            System.out.println(item);
        }
        // join 和 split相反的操作
        String str2 = String.join("-", ips);
        System.out.println(str2);

        System.out.println("    hel  l o   ".trim());
        byte[] bs = str1.getBytes();
        char[] cs = str1.toCharArray();
    }
}
